package com.ngc.mall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ngc.mall.domain.UserDomain;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<UserDomain> {
    @Select("select id from role where id in (select role_id from user_role where user_id = #{userId})")
    List<Long> selectByUserId(@Param("userId") Long userId);

    @Insert({
            "<script>",
            "insert into user_role(user_id,role_id) values",
            "<foreach collection='roleIdList' item='item'  separator=',' >",
            "(#{userId},#{item})",
            "</foreach>",
            "</script>"
    })
    Boolean insertRoleIdsByUserId(@Param("userId") Long userId,@Param("roleIdList") List<Long> roleIdList);

    @Delete("delete from user_role where user_id = #{userId}")
    Boolean deleteRoleByUserId(@Param("userId") Long userId);



}
